use scf.dta, clear


gen byr=year-age

gen sample=(byr>1956 & byr<=1965) // age restricted sample -- NLSY79 cohort

egen la=rowtotal(checking saving mma) // liquid assets
replace la=. if mi(checking, saving, mma)

egen ccbals=rowtotal(tempCCBAL1 tempCCBAL2 tempCCBAL3 tempCCBAL4 tempCCBAL5)  // sum of all credit card balances after last payment is made 

gen m1=finc/12  // generate monthly income

gen p04=(ccbals>0 & la>0) if !mi(ccbals, la)
gen b04=(ccbals>0 & la==0) if !mi(ccbals, la)
gen n04=(ccbals==0 & la==0) if !mi(ccbals, la)
gen s04=(ccbals==0 & la>0) if !mi(ccbals, la)
gen p_2000=(ccbals>0 & la>=m1) if !mi(ccbals, la)  // 1month
gen p_c500_s2000=(ccbals>=500 & la>=m1) if !mi(ccbals, la) // 500 and 1mth
gen p_c500_s500=(ccbals>=500 & la>=500) if !mi(ccbals, la) // 500 and 500

gen s500=(la-ccbal-500)>0
gen s2000=(la-ccbal-m1)>0
gen s_c500_s500=(ccbals<500 & la>=500) if !mi(ccbals, la) // 500 and 500
gen s_c500_s2000=(ccbals<500 & la>=m1) if !mi(ccbals, la) // 0 and 1mth

gen group=p04
replace group=2 if b04==1
replace group=3 if s04==1
replace group=4 if n04==1

label def group 1 "Borrower-Saver" 2 "borrower" 3 "Saver" 4 "neutral"
label val group group

gen group3=p04
replace group3=2 if b04==1 | n04==1
replace group3=3 if s04==1

label def group3 1 "Borrower-Saver" 2 "borrower/neutral" 3 "Saver"
label val group3 group3

gen cpi2012=cpi/229.59402


gen rccdebt=ccbals/cpi2012
gen rliqasset=la/cpi2012
gen rarbitrage=rliqasset-rccdebt

gen rfaminc=finc/cpi2012

rename wgt weight

rename  r_card intrate // interest rate on cc with largest balance

gen edu=1 if ednoHS==1
replace edu=2 if edHS==1
replace edu=3 if edsomeCol==1
replace edu=4 if edCol==1
replace edu=5 if edColp==1

gen ps=1 if p04==1
replace ps=0 if s04==1

label var ps "Borrower-Saver vs Saver, Basic"
label def psl 0 "Saver" 1 "Borrower-Saver"
label value ps psl


gen ps500=1 if p_c500_s2000==1
replace ps500=0 if s_c500_s2000==1

label var ps500 "Borrower-Saver vs Saver, Strict"
label value ps500 psl

// keeping the same percentiles as in 2004

pctile q04=intrate [aw=weight] if group==1 & year==2004 & !mi(intrate), nq(4) genp(qt)
xtile intp=intrate [aw=weight] if year>2003, cutpoints(q04)


gen p1=(ps==1 & intp==1) if !mi(ps, intp)
gen p2=(ps==1 & intp==2) if !mi(ps, intp)
gen p3=(ps==1 & intp==3) if !mi(ps, intp)
gen p4=(ps==1 & intp==4) if !mi(ps, intp)

gen s1=(ps==0 & intp==1) if !mi(ps, intp)
gen s2=(ps==0 & intp==2) if !mi(ps, intp)
gen s3=(ps==0 & intp==3) if !mi(ps, intp)
gen s4=(ps==0 & intp==4) if !mi(ps, intp)



// FIGURE 1

preserve
*keep if year>1994

keep if  year<2013
collapse p04 s04 n04 b04 p_2000 p_c500_s2000 [pw=weight], by(year)
keep if p04!=.


label var p04 "Borrower-Saver"
label var s04 "Saver"
label var n04 "Neutral" 
label var b04 "Borrower" 
 

#delimit ;
twoway (connected p04 year, lcolor(black)  msymbol(diamond) mcolor(black) lwidth(medthick) lpattern(solid))
(connected s04 year, lcolor(black)  msymbol(square) mcolor(black) lwidth(medthick) lpattern(dash) msize(large))
(connected n04 year, lcolor(black) lwidth(medthick) msymbol(circle) mcolor(black) lpattern(shortdash) msize(large) yaxis(2))
(connected b04 year, lcolor(black) lwidth(medthick) lpattern(dash_dot_dot) msymbol(triangle) mcolor(black) msize(large) yaxis(2)),
xlabel(1989 (3) 2010) ylabel(0.35 (0.05) 0.55,grid) ylabel(0 (0.03) 0.18, axis(2)) 
legend(rows(2)) ytitle(Borrower-Saver/Saver) ytitle(Neutral/Borrower, axis(2)) 
title(Full Sample) scheme(s1color);

#delimit cr

graph export SCFgroups.eps, as(eps) preview(off) replace
graph export SCFgroups.pdf, as(pdf) replace

label var p04 "CC debt>0 and liquid savings>0"
label var p_2000 "CC debt>0 and liquid savings>=1mth"
label var p_c500_s2000 "CC debt>=500 and liquid savings>=1mth"

keep if year>=2004 & year<2013

#delimit ;
graph bar (mean) p04  p_2000 p_c500_s2000, over(year) bar(1, color(black)  lcolor(black)) bar(2, fcolor(white) lcolor(black)) bar(3, color(black*0.4)  lcolor(black)) 
legend(label (1 "ccdebt>0 & savings>0") 
label (2 "CC debt>0 & savings>=1mth") 
label (3 "CC debt>=500 & savings>=1mth") region(lstyle(white))) 
ytitle("Share") title("Alternative Definitions of the Borrower-Saver") subtitle("Full Sample")  yscale(range(0 0.53))
blabel(bar, position(outside)  format(%9.2f) color(black)) scheme(s1color);

#delimit cr


graph export SCFp04vsp2000.eps, as(eps) preview(off) replace
graph export SCFp04vsp2000.pdf, as(pdf) replace

restore

// age restricted
preserve
keep if sample==1 & year<2013
*keep if year>1994
collapse p04 s04 n04 b04 p_2000 p_c500_s2000 [pw=weight], by(year)
keep if p04!=.


label var p04 "Borrower-Saver"
label var s04 "Saver"
label var n04 "Neutral" 
label var b04 "Borrower" 
 
#delimit ;
twoway (connected p04 year, lcolor(black)  msymbol(diamond) mcolor(black) lwidth(medthick) lpattern(solid))
(connected s04 year, lcolor(black)  msymbol(square) mcolor(black) lwidth(medthick) lpattern(dash) msize(large))
(connected n04 year, lcolor(black) lwidth(medthick) msymbol(circle) mcolor(black) lpattern(shortdash) msize(large) yaxis(2))
(connected b04 year, lcolor(black) lwidth(medthick) lpattern(dash_dot_dot) msymbol(triangle) mcolor(black) msize(large) yaxis(2)),
xlabel(1989 (3) 2010) ylabel(0.35 (0.05) 0.55,grid) ylabel(0 (0.03) 0.18, axis(2)) 
legend(rows(2)) ytitle(Borrower-Saver/Saver) ytitle(Neutral/Borrower, axis(2)) 
title(Age Restricted Sample) scheme(s1color);

#delimit cr


graph export SCFgroups_age.eps, as(eps) preview(off) replace
graph export SCFgroups_age.pdf, as(pdf) replace

label var p04 "cc debt>0 and liquid savings>0"
label var p_2000 "cc debt>0 and liquid savings>=1mth"
label var p_c500_s2000 "cc debt>=500 and liquid savings>=1mth"

keep if year>=2004

#delimit ;
graph bar (mean) p04  p_2000 p_c500_s2000, over(year) bar(1, color(black)  lcolor(black)) bar(2, fcolor(white) lcolor(black)) bar(3, color(black*0.4)  lcolor(black)) 
legend(label (1 "ccdebt>0 & savings>0") 
label (2 "CC debt>0 & savings>=1mth") 
label (3 "CC debt>=500 & savings>=1mth") region(lstyle(white))) 
ytitle("Share") title("Alternative Definitions of the Borrower-Saver") subtitle("Age Restricted Sample")  yscale(range(0 0.53))
blabel(bar, position(outside)  format(%9.2f) color(black)) scheme(s1color);

#delimit cr

graph export SCFp04vsp2000_age.eps, as(eps) preview(off) replace
graph export SCFp04vsp2000_age.pdf, as(pdf) replace

restore



/// FIGURE 3 

tab q04
****Borrower-Saver vs Saver
preserve
tab intp, gen(intpp)
keep if year<2013
rename ps ps1
gen ps=1 if ps1==0
replace ps=0 if ps1==1
label def ps2 1 "Saver" 0 "Borrower-Saver"
label value ps ps2
collapse intpp1-intpp4 [aw=weight] if year>2003, by(year ps)
drop if ps==.
replace intpp1=intpp1*100
replace intpp2=intpp2*100
replace intpp3=intpp3*100
replace intpp4=intpp4*100
#delimit ;
graph bar intpp1 intpp2 intpp3 intpp4, over(year) by(ps, note("")) bar(1, color(black)  lcolor(black)) bar(2, fcolor(black*0.3) lcolor(black)) bar(3, color(white)  lcolor(black)) bar(4, color(black*0.6)  lcolor(black)) 
legend(label (1 "0-7.9") 
label (2 "7.91-11.16") 
label (3 "11.17-17")
label (4 "17+")) 
ytitle("Share") yscale(range(0 50)) by(, title(Baseline)) subtitle(, nobox)  by(, legend(off))
blabel(bar, position(outside) format(%9.0f) color(black)) scheme(s1color);
#delimit cr
graph save Graph "G1ps.gph", replace
graph export "SCFintratesps.eps", as(eps) preview(off) replace
graph export "SCFintrates_ps.pdf", as(pdf) replace

restore

preserve
tab intp, gen(intpp)
keep if year<2013
collapse intpp1-intpp4 [aw=weight] if year>2003, by(year ps500)
drop if ps500==.
rename ps500 ps500o
gen ps500=1 if ps500o==0
replace ps500=0 if ps500o==1
label def ps2 1 "Saver" 0 "Borrower-Saver"
label value ps500 ps2

replace intpp1=intpp1*100
replace intpp2=intpp2*100
replace intpp3=intpp3*100
replace intpp4=intpp4*100

#delimit ;
graph bar intpp1 intpp2 intpp3 intpp4, over(year) by(ps500, note("")) bar(1, color(black)  lcolor(black)) bar(2, fcolor(black*0.3) lcolor(black)) bar(3, color(white)  lcolor(black)) bar(4, color(black*0.6)  lcolor(black)) 
legend(label (1 "0-7.9") 
label (2 "7.9-11.1") 
label (3 "11.2-17")
label (4 "17+") rows(1)) 
ytitle("Share") yscale(range(0 50)) by(, title(Strict)) subtitle(, nobox)  
blabel(bar, position(outside) format(%9.0f) color(black)) scheme(s1color);
#delimit cr
graph save Graph "G1ps5.gph", replace
graph export "SCFintratesps5.eps", as(eps) preview(off) replace
graph export "SCFintrates_ps5.pdf", as(pdf) replace

restore

//////////////////////////////////////////
***********cost of credit data for Table 9 and Appendix B9
/////////////////////////////////////////

table year intp if ps==1 [pw=weight], c(m intrate m rccdebt m rliqasset m rfaminc)



//// once 2004 values are found, we used a calculator at http://www.bankrate.com/calculators/credit-cards/credit-card-minimum-payment.aspx
///// to compute the cost and the length of time it would take to fully repay the balances.

/// APPENDIX TABLE B8
est clear
/// for baseline definition
reg intrate i.ps#i.year if year>=2004 & !mi(ed, female, black, hisp, othrace, numkid, numad, separated, divorced, widow, single) [pw=weight], robust 
est store y1
areg intrate i.ps#i.year ed female black hisp othrace numkid numad separated divorced widow single if year>=2004 [pw=weight], absorb(age) robust 
est store y2

rename ps ps0   // just to simplify the code for the tables 
rename ps500 ps 
// strict definition

reg intrate i.ps#i.year if year>=2004 & !mi(ed, female, black, hisp, othrace, numkid, numad, separated, divorced, widow, single) [pw=weight], robust 
est store y3
areg intrate i.ps#i.year ed female black hisp othrace numkid numad separated divorced widow single if year>=2004 [pw=weight], absorb(age) robust 
est store y4

#delimit ; 
estout  y*  using "tableSCF.tex", replace  style(tex)   starlevels( * 0.1 ** 0.05 *** 0.01) 
cells(b(star fmt(%5.3fc)) se(par fmt(%5.3fc))) stats(N r2 , fmt(%5.0fc %5.2f) labels("Observations" "R squared"))  varwidth(42) modelwidth(8)
mlabels((1) (2) (3) (4)) collabels(none)
varlabels(_cons "Constant (Saver $\times$ year=2004)" )  msign(--)    label 
order(1.ps#2004.year  1.ps#2007.year 1.ps#2010.year 0.ps#2007.year 0.ps#2010.year _cons)
keep(_cons 1.ps#2004.year 0.ps#2007.year 1.ps#2007.year 0.ps#2010.year 1.ps#2010.year )
prehead("\footnotesize {\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}  \vspace*{1ex} \begin{tabular}{l*{6}{c}} \toprule") 
	posthead("\midrule" " &\multicolumn{2}{c}{Baseline} && \multicolumn{2}{c}{Strict}\\"
"\cline{2-3} \cline{5-6} \\")
	extracols(3)
prefoot("\addlinespace ") 
postfoot("\small{Demographics: }  & No & Yes & & No & Yes \\" "\bottomrule " "\addlinespace " "\end{tabular}"
"\parbox[1]{6.5in}{\footnotesize {\em Notes:} The results are based on the Survey of Consumer Finances data. 
The dependent variable is a dummy variable equal to one if the respondent
is in the borrower-saver group, and zero if a saver. Demographic controls include dummies for age, race, gender, marital status;
completed years of schooling and the number of children and adults in the household. Robust standard errors are reported 
in parentheses. The symbols ***(**)[*] indicate significance at the 1(5)[10] percent level.}}" )   ;	
#delimit cr

rename ps ps500
rename ps0 ps


*******************************************************
/*Zinman (2007) Cost Calculations for Tables 9 and B9*/
*******************************************************


gen sample_1=!mi(rccdebt, intrate, rliqasset)

gen wedge=min(rccdebt,rliqasset)

gen eintrate=(1+intrate/(100*12))^12-1
gen em2own=(1+m2own/(100*12))^12-1

gen cost=wedge*(eintrate-em2own)
gen cost_relative=cost/rfaminc

preserve
keep if group==1
tabstat wedge rccdebt rliqasset intrate rfaminc cost  [aw=weight] if year==2004, by(intp) format(%9.0fc) stats(mean)
tabstat cost  [aw=weight] if year==2004, by(intp) format(%9.0fc) stats(mean p25 median p75) column(variables)
tabstat wedge cost_relative  [aw=weight] if year==2004, by(intp) format(%9.2fc) stats(mean median)

tabstat wedge rccdebt rliqasset intrate rfaminc cost  [aw=weight] if year==2010, by(intp) format(%9.0fc) stats(mean)
tabstat cost  [aw=weight] if year==2010, by(intp) format(%9.0fc) stats(mean p25 median p75) column(variables)
tabstat wedge cost_relative  [aw=weight] if year==2010, by(intp) format(%9.2fc) stats(mean median)

tabstat cost   [aw=weight] if year==2004, stats(mean p25 median p75 max min)
tabstat cost   [aw=weight] if year==2010,  stats(mean p25 median p75 max min)
keep if rfaminc>0
tabstat cost cost_relative  [aw=weight] if year==2004, stats(mean p25 median p75 max min)
tabstat cost cost_relative  [aw=weight] if year==2010,  stats(mean p25 median p75 max min)

restore



